package com.tanhua.houtai.controller;

import cn.hutool.core.collection.CollUtil;
import com.tanhua.common.utils.NoAuthorization;
import com.tanhua.houtai.pojo.AnalysisByDay;
import com.tanhua.houtai.service.HomePageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.websocket.server.PathParam;
import java.util.Date;
import java.util.Map;

@RestController
@RequestMapping("dashboard")
public class homePageController {

    @Autowired
    private HomePageService homePageService;

    /**
     *  首页展示数据  用户累计用户  活跃用户
     * @return
     */
    @GetMapping("summary")
    @NoAuthorization
    public ResponseEntity<Object> summary(@RequestHeader("Authorization")String token){

        Map<String,Object> result = this.homePageService.summary(token);
        if (CollUtil.isNotEmpty(result)) {
            return ResponseEntity.ok(result);
        }
        return null;
    }

    /**
     * 首页展示数据  新增、活跃用户、次日留存率
     *
     * @return
     */
    @GetMapping("users")
    @NoAuthorization
    public ResponseEntity<Object> users(@RequestHeader("Authorization") String token, @PathParam("sd") String sd, @PathParam("ed") String ed, @PathParam("type") String type) {

        Map<String, Object> result = this.homePageService.users(token, sd, ed, type);
        if (CollUtil.isNotEmpty(result)) {
            return ResponseEntity.ok(result);
        }
        return null;
    }
    /**
     * 首页展示数据  注册用户分布，行业top、年龄、性别、地区
     *
     * @return
     */
    @GetMapping("distribution")
    @NoAuthorization
    public ResponseEntity<Object> distribution(@RequestHeader("Authorization") String token, @PathParam("sd") String sd, @PathParam("ed") String ed) {

        Map<String, Object> result = this.homePageService.distribution(token, sd, ed);
        if (CollUtil.isNotEmpty(result)) {
            return ResponseEntity.ok(result);
        }
        return null;
    }
}
